<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */

$birth = strtotime($user->birth);

?>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquerydoubleselectmin.js"></script>
<script type="text/javascript">
var  df = function (id) {
  return "string" == typeof id ? document.getElementById(id) : id;
};

function addEventHandler(oTarget, sEventType, fnHandler) {
  if (oTarget.addEventListener) {
    oTarget.addEventListener(sEventType, fnHandler, false);
  } else if (oTarget.attachEvent) {
    oTarget.attachEvent("on" + sEventType, fnHandler);
  } else {
    oTarget["on" + sEventType] = fnHandler;
  }
};

var Class = {
  create: function() {
  return function() {
    this.initialize.apply(this, arguments);
  }
  }
}

var Extend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}

var DateSelector = Class.create();
DateSelector.prototype = {
  initialize: function(oYear, oMonth, oDay, options) {
  this.SelYear = df(oYear);//年选择对象
  this.SelMonth = df(oMonth);//月选择对象
  this.SelDay = df(oDay);//日选择对象
  
  this.SetOptions(options);
  
  var dt = new Date(), iMonth = parseInt(this.options.Month), iDay = parseInt(this.options.Day), iMinYear = parseInt(this.options.MinYear), iMaxYear = parseInt(this.options.MaxYear);
  
  this.Year = parseInt(this.options.Year) || dt.getFullYear()-18;
  this.Month = 1 <= iMonth && iMonth <= 12 ? iMonth : dt.getMonth() + 1;
  this.Day = iDay > 0 ? iDay : dt.getDate();
  this.MinYear = iMinYear && iMinYear < this.Year ? iMinYear : this.Year;
  this.MaxYear = iMaxYear && iMaxYear > this.Year ? iMaxYear : this.Year;
  this.onChange = this.options.onChange;
  
  //年设置
  this.SetSelect(this.SelYear, this.MinYear, this.MaxYear - this.MinYear + 1, this.Year - this.MinYear);
  //月设置
  this.SetSelect(this.SelMonth, 1, 12, this.Month - 1);
  //日设置
  this.SetDay();
  
  var oThis = this;
  //日期改变事件
  addEventHandler(this.SelYear, "change", function(){
    oThis.Year = oThis.SelYear.value; oThis.SetDay(); oThis.onChange();
  });
  addEventHandler(this.SelMonth, "change", function(){
    oThis.Month = oThis.SelMonth.value; oThis.SetDay(); oThis.onChange();
  });
  addEventHandler(this.SelDay, "change", function(){ oThis.Day = oThis.SelDay.value; oThis.onChange(); });
  },
  //设置默认属性
  SetOptions: function(options) {
  this.options = {//默认值
    Year:   "<?php echo date('Y',$birth);?>",//年
    Month:    "<?php echo date('m',$birth);?>",//月
    Day:    "<?php echo date('d',$birth);?>",//日
    MinYear:  0,//最小年份
    MaxYear:  0,//最大年份
    onChange: function(){}//日期改变时执行
  };
  Extend(this.options, options || {});
  },
  //日设置
  SetDay: function() {
  //取得月份天数
  var daysInMonth = new Date(this.Year, this.Month, 0).getDate();
  if (this.Day > daysInMonth) { this.Day = daysInMonth; };
  this.SetSelect(this.SelDay, 1, daysInMonth, this.Day - 1);
  },
  //select设置
  SetSelect: function(oSelect, iStart, iLength, iIndex) {
  //添加option
  oSelect.options.length = iLength;
  for (var i = 0; i < iLength; i++) { oSelect.options[i].text = oSelect.options[i].value = iStart + i; }
  //设置选中项
  oSelect.selectedIndex = iIndex;
  }
};
</script>
<div class="title">
	<h3>基本资料</h3>
	<ul>
		<li class="current"><a href="?r=setting/base" title="基本资料">基本资料</a></li>
		<li><a href="?r=setting/password" title="修改密码">修改密码</a></li>
		
	</ul>
</div>
<div class="main_content">
	<?php echo CHtml::beginForm('?r=setting/base','post',array('id'=>'editbase'));?>
	<div class="base_infor">
		<span><?php echo $msg;?></span>
		<div class="base_infor_top">
			<div class="left">
				<div class="nick">
					<label>昵&nbsp;&nbsp;&nbsp;&nbsp;称：</label>
					<?php echo CHtml::encode($user->nickname);?>
				</div>
				<div class="nick">
					<label>域&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
					<span>http://zcou.com/<?php echo CHtml::encode($user->subdomain);?></span>
				</div>
				<div class="domain">
					<label>性&nbsp;&nbsp;&nbsp;&nbsp;别：</label>
					<span><?php echo User::getSex($user->sex);?></span>
				</div>
			</div>
			<div class="right">
				<label>我的头像</label>
				<img src="<?php echo Utils::getAvatar($user->avatar);?>" width="115" height="115"/> <a href="?r=setting/avatar" class="modify_btn" title="修改头像">修改头像</a> </div>
			</div>
			<div class="base_infor_bottom">
				<ul>
						
						<li><span class="left"><strong>生&nbsp;&nbsp;&nbsp;&nbsp;日：</strong></span>
							<select id="idYear"></select> 
                			<select id="idMonth"></select> 
                			<select id="idDay"></select>
                			<?php echo CHtml::activeHiddenField($user,'birth',array('id'=>"idShow"));?>
						</li>
						<li><span class="left"><strong>择友性别：</strong></span>
						<input type="radio" name="sex_tendency" value=<?php echo User::SEX_MALE;?> <?php if($setting->sex_tendency==User::SEX_MALE):?>checked=checked<?php endif;?> class='seclect_sex'>
						<span class="left" style="margin-right:10px;"> 男</span>
						<input type="radio" name="sex_tendency" value=<?php echo User::SEX_FEMAL;?> <?php if($setting->sex_tendency==User::SEX_FEMAL):?>checked=checked<?php endif;?> class='seclect_sex'>
						<span class="left" style="margin-right:10px;"> 女</span>
						<input type="radio" name="sex_tendency" value=<?php echo User::SEX_NONE?> <?php if($setting->sex_tendency==User::SEX_NONE):?>checked=checked<?php endif;?> class='seclect_sex'>
						<span class="left"> 不限</span>
						</li>

						<li><span class="left"><strong>城&nbsp;&nbsp;&nbsp;&nbsp;市：</strong></span>
							<?php echo CHtml::activeDropDownList($user,'province_id',array(),array('class'=>'selected_province','id'=>'own_p'))?>
							<?php echo CHtml::activeDropDownList($user, 'city_id', array(),array('class'=>'selected_city','id'=>'own_c','style'=>'width:80px;'))?>

						</li>
						<li><span class="left"><strong>择友年龄：</strong></span>
							<?php echo CHtml::activeDropDownList($setting, 'age_start', array_combine(range(18, 80),range(18, 80)));?>
							
							<span class="left" style="margin-right:10px;">~</span>
							<?php echo CHtml::activeDropDownList($setting, 'age_end', array_combine(array_reverse(range(18, 80)),array_reverse(range(18, 80))));?>

						</li>
						

						<li><span class="left"><strong>学&nbsp;&nbsp;&nbsp;&nbsp;历：</strong></span>
							<?php echo CHtml::activeDropDownList($user,'edu',User::getDegree());?>
						
						</li>
						<li><span class="left"><strong>择友城市：</strong></span>
							<?php echo CHtml::activeDropDownList($setting,'province_id',array(),array('class'=>'province','id'=>'tendency_p'))?>
							<?php echo CHtml::activeDropDownList($setting, 'citys_tendency', array(),array('class'=>'city','id'=>'tendency_c','style'=>'width:80px;'))?>
						</li>
						

						<li><span class="left"><strong>收&nbsp;&nbsp;&nbsp;&nbsp;入：</strong></span>
								<?php echo CHtml::activeDropDownList($user,'income', User::getIncome())?>
							</li>
						<li><span class="left"><strong>择友学历：</strong></span>
							<?php echo CHtml::activeDropDownList($setting,'edu_tendency',User::getDegree());?>
							<span class="left">以上</span> 
						</li>
						

						<li><span class="left"><strong>身&nbsp;&nbsp;&nbsp;&nbsp;高：</strong></span>
								<?php echo CHtml::activeDropDownList($user, 'height', array_combine(range(130, 210),range(130, 210)));?>
							</li>	
						<li><span class="left"><strong>择友收入：</strong></span>
								<?php echo CHtml::activeDropDownList($setting,'income_tendency', User::getIncome())?>
								<span class="left">以上</span>
						</li>
						<li></li>
							
							<li><span class="left"><strong>择友身高：</strong></span>
								<?php echo CHtml::activeDropDownList($setting, 'height_start', array_combine(range(130, 210),range(130, 210)));?>
								<span class="left" style="margin-right:10px;">~</span>
								<?php echo CHtml::activeDropDownList($setting, 'height_end', array_combine(range(130, 210),range(130, 210)));?>
								
							</li>
						</ul>
					</div>
					<div class="base_infor_modify"><span onclick="$('#editbase').submit();" class='validate_check'>修改</span></div>
				</div>
			</div>
		<?php echo CHtml::endForm();?>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#own_p option[value='<?php echo $user->province_id;?>'] ").attr("selected",true);

$("#own_c option[value='<?php echo $user->city_id;?>'] ").attr("selected",true);
$("#tendency_p option[value='<?php echo $setting->province_id;?>'] ").attr("selected",true);
$("#tendency_c option[value='<?php echo $setting->citys_tendency;?>'] ").attr("selected",true);




var ds = new DateSelector("idYear", "idMonth", "idDay", {
  MaxYear: new Date().getFullYear()-18,
  MinYear: new Date().getFullYear() -50,
  onChange: function(){
    var m=this.Month;
    var d=this.Day;
  if(m<10)var m='0'+m; 
  if(d<10)var d='0'+d; 
    $("#idShow").val(this.Year + "-" + m + "-" + d); }
});

ds.onChange();
})
</script>